package com.bdqn.controller;

import com.bdqn.mapper.CategoryMapper;
import com.bdqn.pojo.Category;
import com.bdqn.pojo.Result;
import com.bdqn.service.CategoryService;
import com.bdqn.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;


    /**
     * 添加分类
     * @param category
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Category category) {
        categoryService.add(category);
        return Result.success();
    }

    /**
     * 获取全部
     * @return
     */
    @GetMapping
    public Result<List<Category>> list() {
      List<Category> cs =   categoryService.list();
      return Result.success(cs);
    }

    /**
     * 获取分类信息
     * @param id
     * @return
     */
    @GetMapping("/detail")
    public Result<Category> detail(Integer id) {
       Category c = categoryService.findById(id);
       return Result.success(c);
    }

    /**
     * 更新文章分类
     * @param category
     * @return
     */
    @PutMapping
    public Result update(@RequestBody @Validated Category category) {
        categoryService.update(category);
        return Result.success();
    }

    /**
     * 删除文章分类
     * @param id
     * @return
     */
    @DeleteMapping
    public Result delete(Integer id) {
        categoryService.delete(id);
        return Result.success();
    }
}
